import os
# import matplotlib.pyplot as plt
from tradition import ConvolutionNeuralNet as cnn, LabelProcess as lp, \
    LoadHandWrittenChineseCharacter as lhwcc, Pretreatment as pt
import tensorflow as tf

# tf info
print(tf.__version__)
print(tf.__path__)

# define variable
tail = '.gnt'
current_path = os.getcwd()
train_directory = current_path + "/data/HWDB1.1trn_gnt"
test_directory = current_path + "/data/HWDB1.1tst_gnt"

font_size = 64

# get pic from file and decode tag_code
image_list, image_label, array_count = \
    lhwcc.get_all_images(train_directory, tail)
test_array_list, test_array_label, test_array_count = \
    lhwcc.get_all_images(test_directory, tail)

# label process
image_tag, test_array_tag = lp.label_process(image_label, test_array_label)

# treat all dimensions of the picture as same
image_list = pt.image_resize(image_list, font_size)
test_array_list = pt.image_resize(test_array_list, font_size)

# run model
cnn.convolution_neural_net(image_list, image_tag, array_count,
                           test_array_list, test_array_tag, font_size)

# # show the pic
# plt.figure()
# plt.subplot(1, 2, 1)
# plt.imshow(train_image[0], cmap='gray')
# plt.subplot(1, 2, 2)
# plt.imshow(train_image[1], cmap='gray')
# plt.show()
